<?php

namespace App\Libs\Company\SheetTemplateHandler\Report;

use App\Services\DictService;

class Template110 extends AbstractTemplate
{
    public $dataStartRow = 3;

    public $rules = [
        'column' => [
            'start_row' => 3,
            'end_row' => ['str' => '合计', 'column' => 0],
            'rule' =>
                [
                    ['column' => 1, 'vt' => 3, 'vt_val' => 'StarredHotel'],
                    ['column' => 2, 'vt' => 4, 'vt_val' => ['一星级', '二星级', '三星级', '四星级', '五星级']],
                    ['column' => 3, 'vt' => 1],
                    ['column' => 4, 'vt' => 1],
                    ['column' => 5, 'vt' => 1],
                    ['column' => 6, 'vt' => 2],
                    ['column' => 7, 'vt' => 2],
                    ['column' => 8, 'vt' => 2],
                    ['column' => 9, 'vt' => 1],
                ],
        ],
        'cell' => [

        ],
        'dict' => [
            'start_row' => 3,
            'end_row' => ['str' => '合计', 'column' => 0],
            'rule' => [
                'column' => 1,
                'vt' => 1,
                'vt_val' => 'StarredHotel',
            ],
        ],
    ];

    public function generateReport()
    {
        $this->renderHeader();
        $this->output['sheets']['sheet-01']['cellData']['0']['0'] = $this->createTitleCell('日喀则市' . $this->getDistrictName($this->subTask->district_id) . "{$this->subTask->task->year}年{$this->subTask->task->key}月\r{$this->template->name}");

        $dicts = DictService::getList('StarredHotel', $this->subTask->district_id);
        $sn = 1;
        $this->dataEndRow = $this->dataStartRow;
        foreach ($dicts as $value) {
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][0] = ['v' => $sn++, 's' => 'CENTER'];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][1] = ['v' => $value->dict_code, 's' => 'CENTER'];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][2] = ['v' => $value->extra['星级'] ?? '', 's' => 'CENTER'];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][3] = ['v' => $value->extra['客房数'] ?? '', 't' => 2];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][4] = ['v' => $value->extra['床位数'] ?? '', 't' => 2];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][5] = ['vt' => 1, 't' => 2];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][6] = ['vt' => 2, 't' => 2];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][7] = ['vt' => 2, 't' => 2];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][8] = ['vt' => 2, 't' => 2];
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow][9] = ['vt' => 1, 't' => 2];

            $this->dataEndRow++;
        }

        --$this->dataEndRow;
        $this->renderFooter();
        return $this->output;
    }
}
